<?php

class UserController extends BaseController {

	public function loginForm(){
		echo 'yes, is here';
		echo Input::get( 'age' );
		print_r($_GET);
	}
	
	public function actionLogin() {
		
		if( Session::has('loggedInAs') ) {
			Session::forget('loggedInAs');
		}
				
		$users = User::username(Input::get( 'username') )->first();
		/*$users = User::username(Input::get( 'username' ) )->password(Input::get( 'password' ))				
				->leftJoin('roles', function($join) {
				      $join->on('users.user_role_id', '=', 'roles.id');
				    })
				 ->role( Options::USER_ROLE_ADMIN ) 
				->first();
				*/
		//dd(DB::getQueryLog());
		
		if( empty($users) ) {			
			//return View::make('admin/index', array('status' => 'Login Failed'));
			return Redirect::back()->withErrors(['Account or Password incorrect']);
		} else {
			//set session		
			Session::put('loggedInAs', $users);		
			return Redirect::to('/admin/dashboard'); 
			//return View::make( "admin/dashboard" );
		}
	
	}
	
}